﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoreRay
{
    public abstract class Camera : SceneObject
    {
        protected Camera(Matrix viewMatrix)
        {
            this.ViewMatrix = viewMatrix;
            this.ViewToWorld = this.ViewMatrix.Inverse();
        }

        public Matrix ViewMatrix
        {
            get;
            private set;
        }

        public Matrix ProjectionMatrix
        {
            get;
            private set;
        }

        protected Matrix RasterToView
        {
            get;
            private set;
        }

        protected Matrix ViewToWorld
        {
            get;
            private set;
        }

        public void Init(Film film)
        {
            Matrix rasterToScreenMatrix = Matrix.OrthoOffCenter(0, film.Width, 0, film.Height, 0, 1);

            this.ProjectionMatrix = GenerateProjectionMatrix(film);

            this.RasterToView = rasterToScreenMatrix * this.ProjectionMatrix.Inverse();
        }

        public abstract Matrix GenerateProjectionMatrix(Film film);

        public abstract Ray GenerateRay(Sample sample);
    }
}
